package main

import (
	"encoding/json"
	"fmt"
)

/*
	嵌套并反序列化， 操作一致
*/
type Student struct {
	Id     int    `json:"id"`
	Gender string `json:"gender"`
	Name   string `json:"name"`
	Sno    string `json:"sno"`
}

func main() {
	var s Student
	s.Id = 1
	s.Gender = "男"
	s.Name = "张三"
	s.Sno = "001"
	// 打印结构体
	fmt.Printf("%#v\n", s) // main.Student{Id:1, Gender:"男", Name:"张三", Sno:"001"}

	var json1, _ = json.Marshal(s) // 结构体转换 json
	jsonRes := string(json1)       // 必须要转字符串类型， 否则打印会是 ascii 码
	fmt.Println(jsonRes)           // {"id":1,"gender":"男","name":"张三","sno":"001"}
}
